home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 331_01 / term.c < prev    next >
Text File  |  1990-06-12  |  11KB  |  365 lines

  1. /*
  2. HEADER:         CUG999.12;
  3. TITLE:          Terminal Drivers;
  4. DATE:           10/03/86;
  5.  
  6. DESCRIPTION:   "PC Clone I/O routines for GED editor.
  7.                 Contains calls to assembly routines in file pcio.a.";
  8. SYSTEM:         MS-DOS;
  9. FILENAME:       TERM.C;
  10. WARNINGS:      "O file must be present during link for ged";
  11. AUTHORS:        G. Nigel Gilbert, James W. Haefner, Mel Tearle, G. Osborn;
  12. COMPILERS:      DeSmet C;
  13. */
  14.  
  15. /*
  16.      e/qed/ged screen editor
  17.  
  18.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  19.            August-December 1981
  20.  
  21.     Modified:  Aug-Dec   1984:   BDS-C 'e'(vers 4.6a) to 'qe' (J.W. Haefner)
  22.                March     1985:   BDS-C 'qe' to DeSmet-C 'qed' (J.W. Haefner)
  23.                May       1986;   converted to ged - Mel Tearle
  24.  
  25.     FILE:      term.c
  26.  
  27.     FUNCTIONS: terminit, gotoxy, curson, cleareol, cleareop,
  28.                keytranslate, scrollup, scrolldown,
  29.                colornorm, color1, colorblock, colorerr
  30.  
  31.     PURPOSE:   terminal dependent screen control functions
  32.  
  33. This file in principle contains the functions which must be modified or
  34. rewritten for converting the program to a different terminal or system.
  35. There are several exceptions.  Some modules make direct calls to functions
  36. beginning with scr_ in in pcio.asm.  Those routines conceptually belong
  37. here, but the convesion is not complete.
  38.  
  39. The keyboard input functions would ideally consolidate all the terminal or
  40. system specific code here.  The input processing is in a state of disarray
  41. in this version.  There is some obsolete code and concepts still in the
  42. system.  Consolidation is needed.  There are also places where characters
  43. should be redefined as integers in order to not compromise the 256-symbol
  44. character set.
  45.  
  46. */
  47.  
  48. #include <dos.h>
  49. #include "ged.h"
  50.  
  51. /* control key codes, here for convenience in defining terminal sequences */
  52.  
  53. #define CTRLA   0x01    /*  SOH */
  54. #define CTRLB   0x02    /*  STX */
  55. #define CTRLC   0x03    /*  ETX */
  56. #define CTRLD   0x04    /*  EOT */
  57. #define CTRLE   0x05    /*  ENQ */
  58. #define CTRLF   0x06    /*  ACK */
  59. #define CTRLG   0x07    /*  BEL */
  60. #define CTRLH   0x08    /*  BS  */
  61. #define CTRLI   0x09    /*  HT  */
  62. #define CTRLJ   0x0a    /*  LF  */
  63. #define CTRLK   0x0b    /*  VT  */
  64. #define CTRLL   0x0c    /*  FF  */
  65. #define CTRLM   0x0d    /*  CR  */
  66. #define CTRLN   0x0e    /*  SO  */
  67. #define CTRLO   0x0f    /*  SI  */
  68. #define CTRLP   0x10    /*  DLE */
  69. #define CTRLQ   0x11    /*  DC1 */
  70. #define CTRLR   0x12    /*  DC2 */
  71. #define CTRLS   0x13    /*  DC3 */
  72. #define CTRLT   0x14    /*  DC4 */
  73. #define CTRLU   0x15    /*  NAK */
  74. #define CTRLV   0x16    /*  SYN */
  75. #define CTRLW   0x17    /*  ETB */
  76. #define CTRLX   0x18    /*  CAN */
  77. #define CTRLY   0x19    /*  EM  */
  78. #define CTRLZ   0x1a    /*  SUB */
  79.  
  80. /* --------------------- start here -------------------------- */
  81.  
  82. /*
  83.  *  This function is compiler dependent and must be replaced entirely for
  84.  *  compiling with a different compiler.  The calls to this function
  85.  *  are compiler independent.
  86.  *
  87.  *  Screen output and keyboard input do not pass through this function.
  88.  *  The DOS calls are too slow for screen output.
  89.  *
  90.  *  Some of the calls to this function will work only in the small
  91.  *  data memory model.
  92.  */
  93.  
  94.  
  95. syscall()
  96. {
  97.     int intdos();
  98.     union REGS inregs, outregs;
  99.  
  100. /* set up the hardware registers for passing values to the system */
  101.     inregs.x.ax = rax;
  102.     inregs.x.bx = rbx;
  103.     inregs.x.cx = rcx;
  104.     inregs.x.dx = rdx;
  105.     inregs.x.si = rsi;
  106.     intdos(&inregs, &outregs);
  107.  
  108. /* return the register results to the caller */
  109.     rax = outregs.x.ax;
  110.     rbx = outregs.x.bx;
  111.     rcx = outregs.x.cx;
  112.     rdx = outregs.x.dx;
  113.     rsi = outregs.x.si;
  114.     carryf = outregs.x.cflag;
  115.     return;
  116. }
  117.  
  118.  
  119.  
  120.  
  121. /* sets internal location for start of display address among other things
  122.  */
  123. terminit()
  124. {
  125.     scr_setup();
  126. }
  127.  
  128.  
  129.  
  130. /* move cursor to column x, line y. top left is (0,0)
  131.  */
  132. gotoxy(x,y)
  133. int x,y;
  134. {
  135.     scr_rowcol( y, x);
  136.     return;
  137. }
  138.  
  139. /* cursor on/off
  140.    cursor is turned on if argument is 1; off if 0.  The cursor state that
  141.    existed before the call is returned so that it can be saved by the
  142.    caller for later restoration.
  143.    YES = 1; NO = 0.
  144.  */
  145. curson(onoff)
  146. int onoff;
  147. {
  148.     static int old = -1;
  149.     int i;
  150.  
  151.     if (old == onoff)
  152.         return old;  /* no change */
  153.  
  154.     i = old;
  155.     if(onoff) {
  156.         scr_curson();
  157.         old = 1;
  158.      }
  159.      else {
  160.         scr_cursoff();
  161.         old = 0;
  162.     }
  163.     return i;
  164. }
  165.  
  166. /* write a string and clear from string end to end of line.  x and y are
  167.  * physical coordinates.
  168.  */
  169. writeline(x, y, msg, attrib)
  170. int x, y, attrib;
  171. char *msg;
  172. {
  173.     scr_putstr(x, y, msg, attrib);
  174.     scr_delete(x + strlen(msg), y);
  175.     return;
  176. }
  177.  
  178.  
  179. /* clear to end of line.  x and y are physical cursor addresses (not
  180.  * the variable cursorx).  0 <= x <= SWIDTH,  0 <= y <= SHEIGHT.
  181.  */
  182. cleareol(x,y)
  183. int x, y;
  184. {
  185.     scr_rowcol( y, x);
  186.     scr_clrl();
  187.     return;
  188. }
  189.  
  190.  
  191. /* clear line y and all following lines.  Leave cursor at the start of
  192.  * line y.  y is the physical cursor value, 0 <= y <= SHEIGHT.
  193.  */
  194. cleareop(y)
  195. int y;
  196. {
  197.     gotoxy(0, y);
  198.     scr_cls();
  199.     gotoxy(0, y);
  200.     return;
  201. }
  202.  
  203. /* scroll up 1 line.  Only one-line scrolls are currently supported.  More
  204.  * could be accomodated, but there is no real incentive to.  The argument is
  205.  * the physical cursor y position, 0 <= top <= SHEIGHT.  Lins from there on
  206.  * down are scrolled up one line.  Scrolling is much faster than rewriting.
  207.  * Clears the bottom line if the argument is the bottom line.
  208.  */
  209. scrollup(top)
  210. int  top;
  211. {
  212.     if (top < SHEIGHT)
  213.         scr_scrup( 1, top, 0, SHEIGHT, SWIDTH );
  214.     else
  215.         cleareol(0, SHEIGHT);
  216.     return;
  217. }
  218.  
  219. scrolldown(top)
  220. int  top;
  221. {
  222.     if (top < SHEIGHT)
  223.         scr_scrdn( 1, top, 0, SHEIGHT, SWIDTH );
  224.     return;
  225. }
  226.  
  227. /* set screen character attribute to normal.
  228.  * This control if implemented as a function so that the function can
  229.  * send control characters to the display if the program is ported to
  230.  * a system with a remote terminal.  The overall program still needs quite
  231.  * a bit of work on attribute control.  One function with arguments seems
  232.  * a better way in retrospect.  Some rethinking on attribute control is needed.
  233.  */
  234. colornorm()
  235. {
  236.     attr = ATTR0;
  237.     return attr;
  238. }
  239.  
  240. /* set screen character attribute to highlighted (abnormal).  See
  241.    description in the .h header file. */
  242.  
  243. color1()
  244. {
  245.     attr = ATTR1;
  246.     return attr;
  247. }
  248.  
  249. /* Set screen character attribute to the form used for marking blocks.
  250.  * See the header file.
  251.  */
  252. colorblock()
  253. {
  254.     attr = ATTR2;
  255.     return attr;
  256. }
  257. color3()
  258. {
  259.     attr = ATTR3;  /* underlined, normal intensity */
  260.     return attr;
  261. }
  262. color4()
  263. {
  264.     attr = ATTR4;  /* underlined and highlighted */
  265.     return attr;
  266. }
  267.  
  268.  
  269. /* Set the screen character attribute to the form used for coloring error
  270.  * messages
  271.  */
  272. colorerr()
  273. {
  274.     return colorblock();
  275. }
  276.  
  277.  
  278.  
  279. /*----------------------INPUT FROM KEYBOARD-----------------------------*/
  280.  
  281.  
  282. /* defines the terminal key codes
  283.  * which perform the editor commands
  284.  */
  285. keytranslate()
  286. {
  287. /*
  288.     Keyboard translation has become fragmented.  This table should be
  289.     restructured to allow unrestricted byte value multikey
  290.     commands.  There should also be a place in the table for at
  291.     least one alternate but equivalent key sequence.  The translation
  292.     now done in pcio.asm should probably be moved here.  Code for
  293.     the parity bit described below still exists but is mostly inactive.
  294.     The keyboard characters seen at the top level should
  295.     be convrted to integer type to provide more value flexibility.
  296.     The Microsoft 4.0 convention of signed bytes also complicates
  297.     the use of byte size characters for control purposes.
  298.     The value restrictions are now at the byte limit.      G.O.
  299.  
  300.  */
  301.  
  302. /*
  303.     Each tran[xxxx]= should be set to the code emitted by the terminal
  304.     key which will perform the indicated action.  The recommended (control)